/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.sys;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.domain.po.SysSetPo;
import com.itttq.gshop.generic.connector.ISysSetConnector;

@RestController
@RequestMapping("sys/set")
public class SysSetController extends GenericController {
	private static final long serialVersionUID = 458162097377283469L;
	@Autowired
	private ISysSetConnector sysSiteConnector;
	
	/**
	 * 根据条件查询SysSetPo对象，并分页
	 * 
	 * @param sysSet
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("sets.html")
	public ModelAndView getSysSets(SysSetPo sysSet, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/sys/sets");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		sysSet.setStart(ppt.getStart());
		sysSet.setSize(ppt.getSize());
		ResultPageTo<SysSetPo> rpt = sysSiteConnector.getSysSets(sysSet);
		this.getPageMv("sets", mv, rpt);
		mv.addObject("set", sysSet);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addSysSet() {
		ModelAndView mv = new ModelAndView("/sys/setAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param code
	 * @return
	 */
	@RequestMapping("view/{code}.html")
	public ModelAndView viewSysSet(@PathVariable("code") String code) {
		ModelAndView mv = addSysSet();
		if(code != null) {
			mv.addObject("set", sysSiteConnector.getSysSet(code));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param code
	 * @return
	 */
	@RequestMapping("edit/{code}.html")
	public ModelAndView editSysSet(@PathVariable("code") String code) {
		ModelAndView mv = viewSysSet(code);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存SysSetPo对象，无ID则新增，有ID则更新
	 * 
	 * @param sysSet
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public Integer saveSysSet(SysSetPo sysSet) {
		return sysSiteConnector.saveSysSet(sysSet);
	}

	/**
	 * 根据ID删除SysSetPo对象
	 * 
	 * @param code
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{code}.html")
	@ResponseBody
	public ModelAndView delSysSet(@PathVariable("code") String code) {
		if(code != null) {
			sysSiteConnector.delSysSet(code);
		}
		return getSysSets(new SysSetPo(), null);
	}
}